<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-button
        size="small"
        type="primary"
        title="新增"
        @click="addDsource(false)"
      >
        <i class="fa fa-plus" aria-hidden="true"></i>新增
      </el-button>

    </el-row>
    <el-row :gutter="10">
      <el-table
        :data="tableData"
        :border="true"
        @row-click="selectme">
        <el-table-column label="" :resizable="false" width="35">
          <template slot-scope="scope">
            <el-radio v-model="checked" name="myselect2" :label="scope.row.dsid">&nbsp;
            </el-radio>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          width="150"
          prop="dsname"
          label="名称"
        ></el-table-column>
        <el-table-column
          align="center"
          width="150"
          prop="use"
          label="类型"
        ></el-table-column>
        <el-table-column
          align="center"
          width="150"
          prop="linkType"
          label="数据库"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="linkUrl"
          label="链接字符串"
        ></el-table-column>
        <el-table-column
          align="center"
          width="150"
          prop="linkName"
          label="用户名"
        ></el-table-column>
        <el-table-column width="170" :resizable="true">
            <template slot-scope="scope">
              <el-button
                size="small"
                type="warning"
                title="修改"
                @click="addDsource(true,scope.row.dsid)"
              >
                <i class="el-icon-edit"></i>修改
              </el-button>
              <el-button
                size="small"
                type="danger"
                title="删除"
                @click="delDsource(scope.row.dsid)"
              >
                <i class="el-icon-delete"></i>删除
              </el-button>
            </template>
        </el-table-column>
      </el-table>
    </el-row>
    <dsourceAdd ref="dsourceadd" :isupdate="isupdate"></dsourceAdd>
  </div>
</template>

<script>
import request from "@/utils/request"
import dsourceAdd from "@/views/bi/model/dataSource/dsourceAdd";

export default {
  name: "dsource",
  data() {
    return {
      tableData: [],
      checked: null,
      isupdate: false,
    };
  },
  components: {
    dsourceAdd,
  },
  mounted() {
    this.loadData();
  },
  computed: {},
  methods: {
    selectme(a, b) {
      this.checked = a.dsid;
    },
    //加载列表数据
    loadData() {
      request({
          url: "/bi/model/listDataSource",
          method: "GET",
        }).then(resp=>{
        this.tableData = resp.rows;
      });
    },
    //添加数据源，具体通过子组件实现
    addDsource(isupdate,id) {
      this.isupdate = isupdate;
      this.$refs["dsourceadd"].addDsource(isupdate, id);
    },
    //删除数据源
    delDsource(dsid) {
      this.$confirm("是否确认删除？","提示",{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        request({
            url: "/bi/model/deleteDataSource",
            method: "delete",
            params: {dsid: dsid},
          }).then(resp=>{
          this.$message({
            message: "删除成功！",
            type:"success",
            duration:1500
          });
          this.loadData();
        });
      })
    },
  },
};
</script>

